package com.selfdriving.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.selfdriving.BaseApplication;
import com.selfdriving.BaseObjectListAdapter;
import com.selfdriving.R;
import com.selfdriving.bean.Discuss;
import com.selfdriving.bean.Entity;
import com.selfdriving.utils.Utils;

public class DiscussAdapter extends BaseObjectListAdapter
{
	List<? extends Entity> datas = null;
	Context context;
	BaseApplication application;
	FinalBitmap fb;

	public DiscussAdapter(BaseApplication application, Context context,
			List<? extends Entity> datas)
	{
		super(application, context, datas);
		this.application = application;
		this.datas = datas;
		this.context = context;
		fb = FinalBitmap.create(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolder holder = null;
		if (convertView == null)
		{
			convertView = mInflater.inflate(R.layout.item_discuss, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView
					.findViewById(R.id.discuss_name);
			holder.content = (TextView) convertView
					.findViewById(R.id.discuss_content);
			holder.time = (TextView) convertView
					.findViewById(R.id.discuss_time);
			holder.time = (TextView) convertView
					.findViewById(R.id.discuss_time);
			holder.star = (TextView) convertView
					.findViewById(R.id.discuss_star);

			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		if (datas != null && !datas.isEmpty())
		{
			Discuss notes = (Discuss) datas.get(position);
			String name = notes.getUser();
			String content = notes.getContent();
			String time = notes.getTimes();
			String star = notes.getStar();
			holder.name.setText(name);
			holder.content.setText(content);
			holder.time.setText(Utils.transitionDate(time));
			if (!star.equals("0"))
			{
				holder.star.setText(notes.getStar() + "星");
			}
		}
		return convertView;
	}

	class ViewHolder
	{
		TextView name;
		TextView content;
		TextView star;
		TextView time;
	}
}
